
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 03/26/2012 21:22:44
-- Generated from EDMX file: C:\Documents and Settings\u12113\Mis documentos\Visual Studio 2010\Projects\ProyectoClinica\WSPacienteInfo\SeguroModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Seguro];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_TipoSeguroUsuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UsuarioEstablecer] DROP CONSTRAINT [FK_TipoSeguroUsuario];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioDependiente]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DependienteEstablecer] DROP CONSTRAINT [FK_UsuarioDependiente];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[DependienteEstablecer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DependienteEstablecer];
GO
IF OBJECT_ID(N'[dbo].[TipoSeguroEstablecer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoSeguroEstablecer];
GO
IF OBJECT_ID(N'[dbo].[UsuarioEstablecer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UsuarioEstablecer];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'DependienteEstablecer'
CREATE TABLE [dbo].[DependienteEstablecer] (
    [dni] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL,
    [apellido] nvarchar(max)  NOT NULL,
    [Usuario_dni] int  NOT NULL
);
GO

-- Creating table 'TipoSeguroEstablecer'
CREATE TABLE [dbo].[TipoSeguroEstablecer] (
    [codigo] int IDENTITY(1,1) NOT NULL,
    [descripcion] nvarchar(max)  NOT NULL,
    [coseguro] nvarchar(max)  NOT NULL,
    [deducible] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'UsuarioEstablecer'
CREATE TABLE [dbo].[UsuarioEstablecer] (
    [codigo] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL,
    [apellido] nvarchar(max)  NOT NULL,
    [esTitular] nvarchar(max)  NOT NULL,
    [TipoSeguro_codigo] int  NOT NULL,
    [dni] nvarchar(max)  NOT NULL,
    [telefono] nvarchar(max)  NOT NULL,
    [fechaNacimiento] datetime  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [dni] in table 'DependienteEstablecer'
ALTER TABLE [dbo].[DependienteEstablecer]
ADD CONSTRAINT [PK_DependienteEstablecer]
    PRIMARY KEY CLUSTERED ([dni] ASC);
GO

-- Creating primary key on [codigo] in table 'TipoSeguroEstablecer'
ALTER TABLE [dbo].[TipoSeguroEstablecer]
ADD CONSTRAINT [PK_TipoSeguroEstablecer]
    PRIMARY KEY CLUSTERED ([codigo] ASC);
GO

-- Creating primary key on [codigo] in table 'UsuarioEstablecer'
ALTER TABLE [dbo].[UsuarioEstablecer]
ADD CONSTRAINT [PK_UsuarioEstablecer]
    PRIMARY KEY CLUSTERED ([codigo] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Usuario_dni] in table 'DependienteEstablecer'
ALTER TABLE [dbo].[DependienteEstablecer]
ADD CONSTRAINT [FK_UsuarioDependiente]
    FOREIGN KEY ([Usuario_dni])
    REFERENCES [dbo].[UsuarioEstablecer]
        ([codigo])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioDependiente'
CREATE INDEX [IX_FK_UsuarioDependiente]
ON [dbo].[DependienteEstablecer]
    ([Usuario_dni]);
GO

-- Creating foreign key on [TipoSeguro_codigo] in table 'UsuarioEstablecer'
ALTER TABLE [dbo].[UsuarioEstablecer]
ADD CONSTRAINT [FK_TipoSeguroUsuario]
    FOREIGN KEY ([TipoSeguro_codigo])
    REFERENCES [dbo].[TipoSeguroEstablecer]
        ([codigo])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TipoSeguroUsuario'
CREATE INDEX [IX_FK_TipoSeguroUsuario]
ON [dbo].[UsuarioEstablecer]
    ([TipoSeguro_codigo]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------